﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System.Runtime.InteropServices;

namespace ShootEm.Components
{
    class Score : Microsoft.Xna.Framework.DrawableGameComponent
    {
        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        public static extern uint MessageBox(IntPtr hWnd, String text, String caption, uint type);
        float timer = 0f;
        private int score = 0; 
        private SpriteFont font;
        public Score(ShootEm game)
            : base(game)
        {
        }

        public override void Initialize()
        {
            // TODO: Add your initialization code here
            this.font = this.Game.Content.Load<SpriteFont>("Fonts/font1");
            base.Initialize();
        }
        public void changeScore()
        {
            this.score += 10;
            this.timer = 0f;
        }
        public override void Update(GameTime gameTime)
        {
            if (((ShootEm)this.Game).play)
            {
                timer += (float)gameTime.ElapsedGameTime.TotalMilliseconds;
                if (timer > 10000f)
                {
                    timer = 0f;
                    this.score = 0;
                    MessageBox(new IntPtr(0), "Game over", "Game over", 0);
                    ((ShootEm)this.Game).play = false;
                    this.Game.Components.Add(new PlayNow((ShootEm)this.Game));

                }
            }
           
            base.Update(gameTime);
        }

        public override void Draw(GameTime gameTime)
        {



            ((ShootEm)this.Game).spriteBatch.Begin();
            ((ShootEm)this.Game).spriteBatch.DrawString(font, "SCORE "+this.score, new Vector2(10, 10), Color.White);
            ((ShootEm)this.Game).spriteBatch.DrawString(font, ""+(10-(int)this.timer/1000), new Vector2(950, 10), Color.White);
            ((ShootEm)this.Game).spriteBatch.End();
            base.Draw(gameTime);
        }
    }
}
